<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>购物车</title>

	<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/static/css/cart123.css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/top123.css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/foot123.css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/bootstrap/css/bootstrap-iso.css"/>
	<script type="text/javascript" src="${pageContext.request.contextPath}/static/script/jquery-1.11.2.js"></script>
	<script type="text/javascript">
		$(function () {
			// 给 【删除】绑定单击事件
			$("a.deleteItem").click(function () {
				return confirm("你确定要删除【" + $(this).parent().parent().find("td:first").text() +"】吗?")
			});

			// 给清空购物车绑定单击事件
			$(".clearCar").click(function () {
				return confirm("你确定要清空购物车吗?");
			})

			// 给输入框绑定 onchange内容发生改变事件
			$(".updateCount").change(function () {
				// 获取商品名称
				var name = $(this).parent().parent().find("td:first").text();
				var id = $(this).attr('menuId');
				// 获取商品数量
				var count = this.value;
				if ( confirm("你确定要将【" + name + "】商品修改数量为：" + count + " 吗?") ) {
					//发起请求。给服务器保存修改
					location.href = "http://localhost:8080/user123/updateCount/"+id+"/"+count;
				} else {
					// defaultValue属性是表单项Dom对象的属性。它表示默认的value属性值。
					this.value = this.defaultValue;
				}
			});

		});
	</script>
</head>
<body>
<div class="header">
	<%@include file="../common/top.jsp" %>
</div>

	<div class="div0">
	<div class="cart_img"></div>
	<p class="p1">购物车</p>
	<div class="div1">
		&nbsp;&nbsp;您好呀！亲爱的海绵宝宝&nbsp;&nbsp;
		<a class="aaa" href="http://localhost:8080/user123/menuindex/1">点我继续买买买~</a>
	</div>
</div>
	<div class="div2">
		<div class="div3">
			<table cellspacing="0">
				<thead class="thead">
				<%--				<th class="th1"><input type="checkbox">全选</th>--%>
				<%--				<th class="th2">商品名称</th>--%>
				<th>商品名称</th>
				<th>单价</th>
				<th>数量</th>
				<th>小计</th>
				<th>操作</th>
				</thead>
				<tbody>
				<%--遍历商品信息--%>
				<%--如果购物车为空的情况--%>
				<c:if test="${empty sessionScope.cart.items}">
					<tr>
						<td class="order" colspan="5"><a class="select" href="http://localhost:8080/user123/menuindex/1">亲爱的海绵宝宝，你没有选中任何东西喔~~ 快点我去挑选啦！！</a> </td>
					</tr>
				</c:if>
				<%--如果购物车非空的情况--%>
				<c:if test="${not empty sessionScope.cart.items}">
					<c:forEach items="${sessionScope.cart.items}" var="entry">
						<tr>
								<%--							<td><input type="checkbox"></td>--%>
							<td>${entry.value.name}</td>
							<td>${entry.value.price}</td>
							<td>
								<input class="updateCount"  type="text" menuId="${entry.value.id}" value="${entry.value.count}">
							</td>
							<td>${entry.value.totalPrice}</td>
							<td class="cart_td"><a class="deleteItem" href="http://localhost:8080/user123/deleteItem/${entry.value.id}">删除</a></td>
						</tr>
					</c:forEach>
				</c:if>
				</tbody>
			</table>
		</div>
		<%--如果购物车非空才输出页面的内容--%>
		<c:if test="${not empty sessionScope.cart.items}">
			<div class="div4">
				<a class="clearCar" href="http://localhost:8080/user123/clear">清空购物车</a>
				<div class="div5">
					共有<span class="cart_span">&nbsp;${sessionScope.cart.totalCount}&nbsp;</span>件商品&nbsp;&nbsp;&nbsp;&nbsp;
					总金额为<span class="cart_span">&nbsp;${sessionScope.cart.totalPrice}&nbsp;</span>元
					<span class="cart_button"><a href="${pageContext.request.contextPath}/user123/createOrder">结账</a></span>
				</div>
			</div>
		</c:if>
	</div>
	<div class="div6">
		蟹堡王餐厅.Krusty Krab @2021
	</div>

<div class="foot123">
	<%--静态包含页脚内容--%>
<%--	<%@include file="/pages/common/foot.jsp" %>--%>
</div>
</body>
</html>